//
// Created by spiro on 19-4-9.
//

#include <stdlib.h>
#include "test_prepare.h"

void gen_rand_arr(int * arr, int len) {
    for (int i = 0; i < len; ++i) {
        arr[i] = rand() % len;
    }
}

void gen_ordered_arr(int * arr, int len) {
    for (int i = 0; i < len; ++i) {
        arr[i] = i;
    }
}

void gen_nearly_ordered_arr(int * arr, int len, int swapTimes) {
    int rand_pos1;
    int rand_pos2;

    for (int i = 0; i < len; ++i) {
        arr[i] = i;
    }

    int j = 0;
    int temp;
    while (j < swapTimes) {
        rand_pos1 = rand() % len;
        rand_pos2 = rand() % len;

        if (rand_pos1 == rand_pos2) {
            continue;
        }

        temp = arr[rand_pos1];
        arr[rand_pos1] = arr[rand_pos2];
        arr[rand_pos2] = temp;

        j++;
    }
}

void gen_reverse_arr(int * arr, int len) {
    for (int i = 0; i < len; ++i) {
        arr[i] = (len - i);
    }
}

bool is_sorted(int * arr, int len) {
    for (int i = 1; i < len; ++i) {
        if (arr[i] < arr[i - 1]) {
            return false;
        }
    }
    return true;
}